<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-input
          v-model="query.value"
          clearable
          placeholder="请输入设备名称"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-select
          v-model="query.status"
          clearable
          class="filter-item"
          placeholder="请选择告警状态"
          style="width: 150px"
        >
          <el-option
            v-for="item in dict.gas_warning_status"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
        <el-date-picker
          v-model="query.monitorTime"
          type="daterange"
          :default-time="['00:00:00','23:59:59']"
          range-separator=":"
          size="small"
          class="date-item"
          value-format="yyyy-MM-dd HH:mm:ss"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          @change="change"
        />
        <rrOperation :crud="crud" />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <ul class="tip">
        <li style="color:#FFBA00">
          <img src="../../../assets/images/yellow.png" align="center">不报警
        </li>
        <li style="color:#42b983">
          <img src="../../../assets/images/green.png" align="center">低报警
        </li>
        <li style="color:#FF0000">
          <img src="../../../assets/images/red.png" align="center">高报警
        </li>
      </ul>
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="500px"
      >
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="设备名称">
            <el-input v-model="form.equipmentCode" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="监测时间">
            <el-date-picker v-model="form.monitorTime" type="datetime" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="small"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" align="center" width="55" />
        <el-table-column
          v-if="columns.visible('equipmentCode')"
          align="center"
          prop="equipmentCode"
          label="设备名称"
        />
        <el-table-column
          v-if="columns.visible('monitorTime')"
          align="center"
          prop="monitorTime"
          label="监测时间"
        >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.monitorTime) }}</span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="columns.visible('carbonDioxide')"
          align="center"
          prop="carbonDioxide"
          label="二氧化碳"
        >
          <template slot-scope="scope">
            <span
              v-if="scope.row.carbonDioxideWarningStatus == 0"
              style="color:#FFBA00"
            >{{ scope.row.carbonDioxide }}</span>
            <span
              v-if="scope.row.carbonDioxideWarningStatus == 1 "
              style="color:#42b983"
            >{{ scope.row.carbonDioxide }}</span>
            <span
              v-if="scope.row.carbonDioxideWarningStatus == 2"
              style="color:#FF0000"
            >{{ scope.row.carbonDioxide }}</span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="columns.visible('carbonMonoxide')"
          align="center"
          prop="carbonMonoxide"
          label="一氧化碳"
        >
          <template slot-scope="scope">
            <span
              v-if="scope.row.carbonMonoxideWarningStatus == 0"
              style="color:#FFBA00"
            >{{ scope.row.carbonMonoxide }}</span>
            <span
              v-if="scope.row.carbonMonoxideWarningStatus == 1"
              style="color:#42b983"
            >{{ scope.row.carbonMonoxide }}</span>
            <span
              v-if="scope.row.carbonMonoxideWarningStatus == 2"
              style="color:#FF0000"
            >{{ scope.row.carbonMonoxide }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('oxygen')" align="center" prop="oxygen" label="氧气">
          <template slot-scope="scope">
            <span
              v-if="scope.row.oxygenWarningStatus == 0"
              style="color:#FFBA00"
            >{{ scope.row.oxygen }}</span>
            <span
              v-if="scope.row.oxygenWarningStatus == 1"
              style="color:#42b983"
            >{{ scope.row.oxygen }}</span>
            <span
              v-if="scope.row.oxygenWarningStatus == 2"
              style="color:#FF0000"
            >{{ scope.row.oxygen }}</span>
          </template>
        </el-table-column>
        <el-table-column
          v-if="columns.visible('sulfurettedHydrogen')"
          align="center"
          prop="sulfurettedHydrogen"
          label="硫化氢"
        >
          <template slot-scope="scope">
            <span
              v-if="scope.row.sulfurettedHydrogenWarningStatus == 0"
              style="color:#FFBA00"
            >{{ scope.row.sulfurettedHydrogen }}</span>
            <span
              v-if="scope.row.sulfurettedHydrogenWarningStatus == 1"
              style="color:#42b983"
            >{{ scope.row.sulfurettedHydrogen }}</span>
            <span
              v-if="scope.row.sulfurettedHydrogenWarningStatus == 2"
              style="color:#FF0000"
            >{{ scope.row.sulfurettedHydrogen }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('methane')" align="center" prop="methane" label="甲烷">
          <template slot-scope="scope">
            <span
              v-if="scope.row.methaneMonoxideWarningStatus == 0"
              style="color:#FFBA00"
            >{{ scope.row.methane }}</span>
            <span
              v-if="scope.row.methaneMonoxideWarningStatus == 1"
              style="color:#42b983"
            >{{ scope.row.methane }}</span>
            <span
              v-if="scope.row.methaneMonoxideWarningStatus == 2"
              style="color:#FF0000"
            >{{ scope.row.methane }}</span>
          </template>
        </el-table-column>
        <!--        <el-table-column-->
        <!--          v-permission="['admin','gasMonitorHistory:edit','gasMonitorHistory:del']"-->
        <!--          label="操作"-->
        <!--          width="150px"-->
        <!--          align="center"-->
        <!--        >-->
        <!--          <template slot-scope="scope">-->
        <!--            <udOperation :data="scope.row" :permission="permission" />-->
        <!--          </template>-->
        <!--        </el-table-column>-->
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudGasMonitorHistory from '@/api/sapientialSite/gasMonitorHistory'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
// import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

// crud交由presenter持有
const defaultCrud = CRUD({
  title: '气体监测历史数据',
  url: 'api/gasMonitorHistory',
  sort: 'id,desc',
  crudMethod: { ...crudGasMonitorHistory }
})
const defaultForm = {
  id: null,
  equipmentCode: null,
  monitorTime: null,
  carbonDioxide: null,
  carbonDioxideWarningStatus: null,
  carbonMonoxide: null,
  carbonMonoxideWarningStatus: null,
  oxygen: null,
  oxygenWarningStatus: null,
  sulfurettedHydrogen: null,
  sulfurettedHydrogenWarningStatus: null,
  methane: null,
  methaneMonoxideWarningStatus: null,
  createUser: null,
  createDate: null,
  updateUser: null,
  updateDate: null,
  isDelete: null
}
export default {
  name: 'GasMonitorHistory',
  components: { pagination, crudOperation, rrOperation },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  // 数据字典
  dicts: ['gas_warning_status'],
  data() {
    return {
      permission: {
        add: ['admin', 'gasMonitorHistory:add'],
        edit: ['admin', 'gasMonitorHistory:edit'],
        del: ['admin', 'gasMonitorHistory:del']
      },
      rules: {}
    }
  },
  created() {
    this.crud.optShow = {
      add: false,
      edit: false,
      del: false
    }
  },
  methods: {
    // 格式化日期
    change() {
      console.log(this.monitorTime)
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      const query = this.query
      this.crud.params = {}
      if (query.value) {
        this.crud.params['equipmentCode'] = query.value
      }
      if (query.monitorTime) {
        this.crud.params['monitorTime'] = query.monitorTime
      }
      if (query.status) {
        this.crud.params['gasWarningStatus'] = query.status
      }
      // if (query.type && query.value) {
      //   this.crud.params[query.type] = query.value
      // }
      return true
    }
  }
}
</script>

<style lang="scss" scoped>
.tip {
  width: 50%;
  margin-top: -25px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  list-style: none;
  height: 30px;
  line-height: 30px;
  margin-left: -40px;
  li {
    padding-left:10px;
    font-size: 15px;
  }
  .title {
    font-size: 15px;
    font-weight: 100;
    color: #ff0000;
  }
}
</style>
